package com.wang.bootbuilder.controller.execl;

import com.alibaba.excel.EasyExcel;
import com.wang.bootbuilder.entity.dto.ExeclDictDto;
import com.wang.bootbuilder.service.DictService;
import com.wang.bootbuilder.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/manage/operate")
public class ExeclOperateController {

    @Autowired
    DictService dictService;

    @GetMapping("/download")
    public void batchDownLoad(HttpServletResponse response) throws IOException {
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        String fileName = "Category" + StringUtils.UNDERSCORE + StringUtils.getCurrentDateStr();
        response.setHeader("Content-disposition", "attachment;filename*=" + fileName + ".xlsx");
        EasyExcel.write(response.getOutputStream(), ExeclDictDto.class).sheet("分类信息").doWrite(dictService.listDictData());
    }

}
